<template>
	<view class="paySuccess">
		<view class="img-desc">
			<image src="../../static/icon/image_32.png" mode=""></image>
			<view class="desc">
				{{$t("paySuccess.title")}}
			</view>
		</view>

		<view class="footer">
			<view class="go-where" @tap="myOrder">
				{{$t("paySuccess.lookOrder")}}
			</view>

			<view class="go-where" @tap="goHome">
				{{$t("paySuccess.goHome")}}
			</view>

			<view class="question">
				{{$t("paySuccess.hint1")}}<text style="color: #009EE3;">{{$t("paySuccess.hint2")}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { goPaypalParms, getUserCid } from "@/common/api.js"

	export default {
		data() {
			return {
				parms: {
					PayerID: "",
					paymentId: "",
					token: ""
				},
				isClick: false,
				cid1: null,
				cid2: null
			}
		},
		methods: {
			myOrder() {
				// #ifdef APP
				uni.redirectTo({
					url:"/pages/myOrder/myOrder"
				})
				// #endif
				// #ifdef H5
				if(!this.isClick) {
					uni.showToast({
						icon: 'none',
						title: this.$t('confirmGoodsOrder.hint1'),
						duration: 5
					})
					return
				}
				uni.redirectTo({
					url:"/pages/myOrder/myOrder"
				})
				// #endif
			},
			goHome() {
				// #ifdef APP
				uni.switchTab({
					url:'/pages/home/home'
				})
				// #endif
				// #ifdef H5
				if(!this.isClick) {
					uni.showToast({
						icon: 'none',
						title: this.$t('confirmGoodsOrder.hint1'),
						duration: 5
					})
					return
				}
				uni.switchTab({
					url:'/pages/home/home'
				})
				// #endif
			},
			async initParms() {
				if(!this.parms.PayerID) return
				const res = await goPaypalParms(this.parms);
				console.log(res);
				if(res) {

					this.isClick = true;
				}
			},
			notice() {
				// #ifdef APP
				console.log(this.cid1, this.cid2);
				uniCloud.callFunction({
					name: "push",
					data: {
						cids: this.cid1,
						title: this.$t('appNotice.title'),
						content: this.$t(
							'appNotice.paySuccess')
					},
					success: (res) => {
						console.log(res);
					},
					fail: (f) => {
						console.log(f);
					}
				})
				uniCloud.callFunction({
					name: "push",
					data: {
						cids: this.cid2,
						title: this.$t('appNotice.title'),
						content: this.$t(
							'appNotice.deliver')
					},
					success: (res) => {
						console.log(res);
					},
					fail: (f) => {
						console.log(f);
					}
				})
				// #endif
			}
		},
		onLoad(option) {
			console.log(option);
			this.parms.PayerID = option.PayerID;
			this.parms.paymentId = option.paymentId;
			this.parms.token = option.token;
			this.cid1 = option.cid1;
			this.cid2 = option.cid2;
			this.notice();
			this.initParms();
		},
		onReady() {
			uni.setNavigationBarTitle({ title: this.$t("paySuccess.title")});
		},
		onBackPress(e) {
			uni.switchTab({
				url: "/pages/home/home"
			})
			return true;
		},
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}
</style>
<style lang="scss" scoped>
	.img-desc {
		padding-top: 500rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;

		image {
			width: 130rpx;
			height: 130rpx;
			margin: 0 auto;
		}

		.desc {
			margin-top: 56rpx;
			font-family: 'PingFang SC';
			font-style: normal;
			font-weight: 700;
			font-size: 50rpx;
			text-align: center;
		}
	}

	.footer {
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 550;
		font-size: 36rpx;
		color: #858585;
		position: absolute;
		bottom: 40rpx;
		width: 100%;

		.go-where {
			background: #FFFFFF;
			box-shadow: 0px 2rpx 16rpx rgba(0, 0, 0, 0.1);
			border-radius: 20rpx;
			margin: 0 24rpx;
			margin-bottom: 30rpx;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
		}

		.question {
			text-align: center;
		}
	}
</style>
